const express = require("express");

const app = express();

//中间件
app.use(express.static("./www"));

// 解码 urlencoded
app.use(express.urlencoded());

// 解码 json
app.use(express.json());

app.get("/users", (req, res) => {
  res.send({
    method: req.method,
    path: req.path,
    query: req.query,
  });
});

// /users/100/room/200
// app.get("/users/:uid/room/:rid", (req, res) => {
//   res.send({
//     method: req.method,
//     path: req.path,
//     query: req.query,
//     params: req.params,
//   });
// });

// /users/100/room/200
app.post("/users/:uid/room/:rid", (req, res) => {
  res.send({
    method: req.method,
    path: req.path,
    query: req.query,
    params: req.params,
    body: req.body,
    header: req.headers,
  });
});

// 设置端口
const port = 3008;
app.listen(port, () => {
  console.log(`http://192.168.1.42:${port}`);
});
